package com.dabai.uitools.utils;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;

/**
 * Description : Other
 *
 * @author BAI
 */
public class BitmapUtils {


    /**
     * 位图切割顶部
     *
     * @param bitmap    位图
     * @param topHeight 顶层高度
     * @return {@link Bitmap}
     */
    public static Bitmap bitmapCuttingTop(Bitmap bitmap,int topHeight) {
        Bitmap newbm = null;
        if (bitmap!=null){
            // 获得图片的宽高
            int width = bitmap.getWidth();
            int height = bitmap.getHeight();

            newbm = Bitmap.createBitmap(bitmap, 0, topHeight, width, height-topHeight);
        }
        return newbm;
    }


    /**
     * 位图横向拼接
     * 横向拼接
     *
     * @param first  第一个
     * @param second 第二个
     * @return {@link Bitmap}
     */
    public static Bitmap bitmapHorizontalSplices(Bitmap first, Bitmap second) {
        int width = first.getWidth() + second.getWidth();
        int height = Math.max(first.getHeight(), second.getHeight());
        Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(result);
        canvas.drawBitmap(first, 0, 0, null);
        canvas.drawBitmap(second, first.getWidth(), 0, null);
        return result;
    }


    /**
     * 位图垂直拼接
     * 纵向拼接
     *
     * @param first  第一个
     * @param second 第二个
     * @return {@link Bitmap}
     */
    public static Bitmap bitmapVerticalSplices(Bitmap first, Bitmap second) {
        int width = Math.max(first.getWidth(),second.getWidth());
        int height = first.getHeight() + second.getHeight();
        Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(result);
        canvas.drawBitmap(first, 0, 0, null);
        canvas.drawBitmap(second, 0,first.getHeight(), null);
        return result;
    }



}
